package edu.dhbw.mannheim;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.users.User;

public class NameDate {
	/**
	 * returns a header for posts and blogs with the users name and the date
	 * @param post
	 * @return
	 */
	public static String getNameDateHTML(Entity post) {
		String output ="";
		output+="<table class=\"fullwidth\">"+
			"<tr>"+
				"<td class=\"left\">";
				 	SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yy HH:mm");
					if (post.getProperty("user") == null) {
						output+="<p>An anonymous person wrote:</p>";
					} else {
						String username = ((User) post.getProperty("user")).getEmail();
						output+="<p><a href='blog.jsp?type=listposts&filter="+
								username+"'>" + username + "</a>" +
								"</b> wrote:</p>";
					}
					output+="</td>"+
							"<td class=\"right\">" +
								formatter.format((Date)post.getProperty("date")) +
							"</td>"+
			"</tr>"+
		"</table>";
		return output;
	}
}
